package com.lrkj.task;

import com.lrkj.common.constant.FeeConstants;
import com.lrkj.common.utils.LrkjDateUtil;
import com.lrkj.common.utils.uuid.IdUtils;
import com.lrkj.payfee.domain.RoomNorm;
import com.lrkj.payfee.domain.RuleCost;
import com.lrkj.payfee.service.IRoomNormService;
import com.lrkj.payfee.service.IRuleCostService;
import com.lrkj.payfee.service.ITollCenterService;
import com.lrkj.payfee.vo.NormChargeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

/***
 * 2022-03-24
 * yajun_ren
 * 收费模块,定时任务
 *
 * **/
@Component("payfeeTask")
public class PayfeeTask {


    @Autowired
    private IRoomNormService roomNormService;

    @Autowired
    private IRuleCostService ruleCostService;

    @Autowired
    private ITollCenterService tollCenterService;


    /***
     * 自动计算常规费用
     *
     * ***/
    @Transactional
    public void routineFeeComputing() {
//        List<RuleCost> savaRuleCosts = new ArrayList<>();
//        List<RoomNorm> updateRoomNorms = new ArrayList<>();
//        //1、查询房屋收费标准(常规费用)
//        NormChargeVo eg = new NormChargeVo();
//        Date lastMonthDay = LrkjDateUtil.getLastMonthDay(new Date());
//        eg.setStatus(FeeConstants.room_norm_status_10001);
//        eg.setProjectId(FeeConstants.charge_project_01);
//        eg.getParams().put("deliveryTimeLT", LrkjDateUtil.getFormatTimeString(lastMonthDay, LrkjDateUtil.DATE_FORMATE_STRING_B));
//        eg.getParams().put("notNullOwnerId", "Y");
//        List<NormChargeVo> roomNorms = roomNormService.selectArrearageRoomNorm(eg);
//        roomNorms.stream().forEach(x -> {
//            //交乞年月 -- 为了防止创建费用单对象的时候把交乞年月重新赋值 , 这里先复制下来
//            Date deliveryTime = x.getDeliveryTime();
//
//            //获取需要生成的费用单费用区间
//            List<Map<String, Date>> costCycle = tollCenterService.getCostCycle(x, lastMonthDay);
//            if (null != costCycle && costCycle.size() > 0) {
//                costCycle.stream().forEach(map -> {
//                    RuleCost ruleCost = tollCenterService.createRuleCost(x, map);
//                    ruleCost.setCostId(IdUtils.simpleUUID());
//                    ruleCost.setRoomName(x.getRoomName());
//                    ruleCost.setOwnerName(x.getCustomName());
//                    ruleCost.setNormNames(x.getNormNames());
//                    savaRuleCosts.add(ruleCost);
//                });
//                RuleCost lastRuleCost = savaRuleCosts.get(savaRuleCosts.size() - 1);
//                RoomNorm updateRoomNorm = tollCenterService.createUpdateRoomNorm(x, lastRuleCost);
//                updateRoomNorm.setDeliveryTime(deliveryTime);
//                updateRoomNorms.add(updateRoomNorm);
//            }
//        });
//        if (null != savaRuleCosts && savaRuleCosts.size() > 0) {
//            ruleCostService.doSaveList(savaRuleCosts);
//        }
//        if (null != updateRoomNorms && updateRoomNorms.size() > 0) {
//            roomNormService.updateByBatch(updateRoomNorms);
//        }

        //添加费用生成记录
    }

}
